package com.springweb.unit2.annotated;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.springweb.unit2.annotated.impl.AnotherCDPlayer;
import com.springweb.unit2.annotated.impl.HardDaysNight;
import com.springweb.unit2.annotated.impl.Masonry;
import com.springweb.unit2.annotated.impl.Revolver;
import com.springweb.unit2.annotated.impl.SecondCDPlayer;

@Configuration
//@ComponentScan(basePackages={"com.springweb.unit2"})
//@ComponentScan(basePackageClasses={CompactDisc.class, SgtPeppers.class, CDPlayer.class})
public class CDPlayerConfig {
	
	@Bean("masonry")
	public CompactDisc masonry() {
		return new Masonry();
	}
	
	@Bean("randomBeatlesCD")
	public CompactDisc randomBeatlesCD() {
		int choice = (int) Math.floor(Math.random()*3);
		CompactDisc result = null;
		switch (choice) {
		case 0:
			result = new Masonry();
			break;
		case 1:
			result = new Revolver();
			break;
		default:
			result = new HardDaysNight();
			break;
		}
		return result;
	}
	
	/**
	 * 
	 * Description: 构造函数注入
	 *
	 * @return
	 * @Author zhangxujun
	 * @Create Date: 2017年11月8日 下午3:03:27
	 */
	@Bean("anotherCDPlayer")
	public MediaPlayer anotherCDPlayer() {
		return new AnotherCDPlayer(randomBeatlesCD());
	}
	
	/**
	 * 
	 * Description: Seter方法注入
	 *
	 * @param randomBeatlesCD
	 * @return
	 * @Author zhangxujun
	 * @Create Date: 2017年11月8日 下午3:03:41
	 */
	@Bean("secondCDPlayer")
	public MediaPlayer secondCDPlayer(CompactDisc randomBeatlesCD) {
		System.out.println("create secondCDPlayer");
		SecondCDPlayer result = new SecondCDPlayer();
		result.setCd(randomBeatlesCD);
		return result;
	}
}
